package io.renren.modules.wx.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.modules.wx.dao.StudentDao;
import io.renren.modules.wx.entity.StudentEntity;
import io.renren.modules.wx.service.StudentService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("studentService")
public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> implements StudentService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String key = (String) params.get("key");
        String classId = (String) params.get("classId");
        QueryWrapper<StudentEntity> wrapper = null;

        if (!StringUtils.isBlank(key)) {
            wrapper = new QueryWrapper<StudentEntity>().like("username", key);
        } else if (!StringUtils.isBlank(classId)) {
            wrapper = new QueryWrapper<StudentEntity>().eq("class_id", classId);
        }

        IPage<StudentEntity> page = this.page(
                new Query<StudentEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }

}